<%--
  Created by IntelliJ IDEA.
  User: gaosubo3000
  Date: 2020/10/12
  Time: 10:12
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>项目开标</title>
    <script src="/lib/layui/layui/layui.js"></script>
    <link rel="stylesheet" href="/lib/laydate/skins/default/laydate.css">
    <link rel="stylesheet" href="/lib/layui/layui/css/layui.css?20190817.1">
    <link rel="stylesheet" href="/lib/layer/skin/default/layer.css">
    <script type="text/javascript" src="../../js/news/jquery-1.9.1.js"></script>
    <script src="../../lib/pagination/js/jquery.pagination.min.js" type="text/javascript" charset="utf-8"></script>
    <%--    <script src="../../lib/layer/layer.js?20201106"></script>--%>
    <script src="../../lib/laydate/laydate.js"></script>
    <script src="/lib/layui/layui/layui.js"></script>
</head>
<style>
    .luIn{
        height: 115px;
        margin-top: 10px;
        margin-right: 10px;
    }
    .header{
        margin-top: 15px;
        height: 35px;
        margin: 20px;
    }
    .header .title{
        margin-left: 22px;
    }
    .header span{
        float: none;
        font-size: 22px;
        color: #333;
        display: inline-block;
        margin-left: 10px;
        vertical-align: middle;
        margin-top: -6px;
    }
</style>
<body>
<div class="header">
    <div class="title">
        <img src="/img/commonTheme/${sessionScope.InterfaceModel}/flow_run_title.png"><span style="">项目开标</span>
        <hr style="background-color: black"/>
    </div>
</div>
<div class="box" style="margin: 0 15px;margin-left: 22px;">
    <table id="demo" lay-filter="test"></table>
</div>
</body>
</html>
<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-xs layui-btn-danger" style="width: 28%;" lay-event="opening">开标</a>
    <a class="layui-btn layui-btn-xs layui-btn-light" style="background-color:#2B7FE0;width: 37%" lay-event="endOpening">结束开标</a>
</script>
<script type="text/html" id="barDemo2">
    <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="evaluation">录入评标结论</a>
    {{#  if(d.hitStatus != 1){ }}
    <a class="layui-btn layui-btn-xs layui-btn-light" style="background-color:#2B7FE0;" lay-event="winning">选为中标</a>
    {{#  } }}

    {{#  if(d.hitStatus == 1){ }}
    <a class="layui-btn layui-btn-xs layui-btn-light" style="background-color:#2B7FE0;" lay-event="cancel">取消中标</a>
    {{#  } }}
</script>
<script>
    layui.use('table', function() {
        var table = layui.table;
        table.render({
            elem: '#demo'
            ,url: '/biddingInfo/getBiddingInfo?status='+3 //数据接口
            ,page: true //开启分页
            ,cols: [[
                {field:'projectNo', title:'项目编号'}
                ,{field:'projectName', title:'项目名称'}
                ,{field:'releaseDate', title:'发布日期'}
                ,{field:'purchaseDeptName', title:'采购部门'}
                ,{field:'infoDesc', title:'详细要求'}

                ,{field:'biddingBeginDate', title:'投标开始日期'}
                ,{field:'biddingEndDate', title:'投标结束日期'}
                ,{field:'attachmentName', title:'投标文件'}
                ,{field:'status', title:'状态',templet: function (d) {
                        var status = d.status
                        if(status == 1){
                            return status = '未发布'
                        }else if(status == 2){
                            return status = '已发布'
                        }else if(status == 3){
                            return status = '开标中'
                        }else {
                            return status = '结束'
                        }
                    }}
                ,{title:'操作', toolbar: '#barDemo',align:'center'}
            ]]
            ,parseData: function(res){ //res 即为原始返回的数据
                return {
                    "code": 0, //解析接口状态
                    "msg": res.msg, //解析提示文本
                    "count": res.totleNum, //解析数据长度
                    "data": res.obj //解析数据列表
                };
            }
        });

        table.on('tool(test)', function(obj) {
            var data = obj.data;
            var layEvent = obj.event;
            if(layEvent === 'opening'){
                layer.open({
                    type: 1
                    , area: ['80%', '80%']
                    , title: '查看投标'
                    , content: '<div class="layui-form" id="findStock" style="margin:10px 20px">' +
                        '<table class="layui-hide" id="store" lay-filter="store"></table>\n'+
                        '</div>'
                    , btn: ['返回']
                    ,success:function(res){
                        table.render({
                            elem: '#store',
                            url:'/TenderInfo/getTenderInfo',
                            where:{
                                tenderStatus:3,
                                biddingId:data.biddingId
                            },
                            parseData: function(res){
                                return {
                                    "code":0,
                                    "data": res.obj,
                                };
                            },
                            cols: [[
                                {field:'projectNo', title:'项目编号',templet:function(d){
                                        if(d.crmBiddingInfo != undefined){
                                            return d.crmBiddingInfo.projectNo
                                        }else {
                                            return ''
                                        }

                                    }}
                                ,{field:'projectName', title:'项目名称',templet:function(d){
                                        if(d.crmBiddingInfo != undefined) {
                                            return d.crmBiddingInfo.projectName
                                        }else {
                                            return  ''
                                        }
                                    }}
                                ,{field:'userName', title:'供货商'}
                                ,{field:'tenderStatus', title:'投标状态',templet:function(d){
                                        var status = d.tenderStatus
                                        if(status == 0){
                                            return '未查看'
                                        }else if(status == 1){
                                            return '未完成'
                                        }else {
                                            return '完成'
                                        }
                                    }}
                                ,{field:'endDate', title:'完成投标日期'}
                                ,{field:'attachmentName', title:'投标文件'}
                                ,{field:'hitStatus', title:'状态',templet: function (d) {
                                        // console.log(d)
                                        var hitStatus = d.hitStatus
                                        if(hitStatus == 0){
                                            return hitStatus = '待定'
                                        }else if(hitStatus == 1){
                                            return hitStatus = '中标'
                                        }else {
                                            return hitStatus = '未中标'
                                        }
                                    }}
                                ,{fixed: '', title:'操作', toolbar: '#barDemo2',width:250,align:'center'}
                            ]]
                            ,page: false,
                        });
                    },
                    yes:function(index){
                        window.location.reload()
                    }
                });
            }else if(layEvent === 'endOpening'){

                layer.confirm('确定结束投标吗？', {
                    btn: ['确定','取消'] //按钮
                }, function()
                {
                    // layer.closeAll('dialog');
                    $.ajax({
                        url:'/biddingInfo/editBiddingInfo',
                        dataType: 'json',
                        type: 'get',
                        data:{
                            biddingId:data.biddingId,
                            status:4,
                        },
                        success:function (res) {
                            layer.alert('结束开标成功！', {icon: 1})
                            window.location.reload()
                            // table.reload()
                            layer.closeAll();
                        }

                    })
                });
                // $.ajax({
                //     url:'/biddingInfo/editBiddingInfo',
                //     dataType: 'json',
                //     type: 'get',
                //     data:{
                //         biddingId:data.biddingId,
                //         status:4,
                //     },
                //     success:function (res) {
                //         layer.msg('结束开标成功！', {icon: 1})
                //         table.reload('demo')
                //     }
                // })
            }
        })

        table.on('tool(store)', function(obj) {
            var data = obj.data;
            var layEvent = obj.event;
            if(layEvent === 'evaluation'){
                layer.open({
                    type: 1,
                    title: '录入评标结论',
                    btn: ['确定', '取消'],
                    shade: 0.5,
                    maxmin: true, //开启最大化最小化按钮
                    area: ['30%', '50%'],
                    content:'<div class="layui-form-item layui-form-text luIn">\n' +
                        '    <label class="layui-form-label" style="padding-left: 0;width:90px;">录入评标结论</label>\n' +
                        '    <div class="layui-input-block">\n' +
                        '      <textarea name="desc" placeholder="请输入内容" class="layui-textarea lastDesc"></textarea>\n' +
                        '    </div>\n' +
                        '  </div>',
                    success: function (res) {
                        if (data.lastDesc){
                            $('textarea[name="desc"]').val(data.lastDesc);
                        }
                    },
                    yes:function (index) {
                        $.ajax({
                            url:'/TenderInfo/editTenderInfo',
                            dataType: 'json',
                            type: 'post',
                            data:{
                                tenderId:data.tenderId,
                                status:4,
                                lastDesc:$('.lastDesc').val()
                            },
                            success: function (res) {
                                // table.reload('store')
                                window.location.reload()
                                layer.close(index);
                            },
                        })
                    }
                })

            }else if(layEvent === 'winning'){
                $.ajax({
                    url: '/TenderInfo/editTenderInfo',
                    dataType: 'json',
                    type: 'get',
                    data: {
                        tenderId: data.tenderId,
                        hitStatus: 1,

                    },
                    success: function (res) {
                        layer.msg('选为中标成功！', {icon: 1})
                        // table.reload('store')
                        window.location.reload()
                    }
                })

            }else if(layEvent === 'cancel'){
                $.ajax({
                    url: '/TenderInfo/editTenderInfo',
                    dataType: 'json',
                    type: 'get',
                    data: {
                        tenderId: data.tenderId,
                        hitStatus: 2,

                    },
                    success: function (res) {
                        layer.msg('取消中标成功！', {icon: 1})
                        window.location.reload()
                        // table.reload('store')
                    }
                })
            }

        })
    })
</script>
